package service

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"net/http"
	"video-srv/basic/golbal"
	"video-srv/handler/request"
	"video-srv/model"
)

func VideoAdd(c *gin.Context) {

	add := request.VideoAdd{}
	err := c.ShouldBind(&add)
	if err != nil {
		return
	}

	video := model.Video{

		Title:     add.Title,
		Class:     add.Class,
		Label:     add.Label,
		Image_Url: add.Image_url,
	}

	golbal.DB.Debug().Create(&video)

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "视频发布成功",
	})
}

func UpdateVideo(c *gin.Context) {
	add := request.UpdateVideo{}
	err := c.ShouldBind(&add)
	if err != nil {
		return
	}

	video := model.Video{
		Model:     gorm.Model{ID: uint(add.Id)},
		Title:     add.Title,
		Class:     add.Class,
		Label:     add.Label,
		Image_Url: add.Image_url,
		Status:    add.Status,
	}
	golbal.DB.Debug().Updates(&video)

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "状态修改成功",
	})
}
